package com.example.mongoreactive.service;

import com.example.mongoreactive.model.User;
import com.example.mongoreactive.respository.UserRepository;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service
public class UserService {
    private final UserRepository userRepository;
    
    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }
    
    public Mono<User> createUser(User user) {
        return userRepository.save(user);
    }
    
    public Mono<User> getUserByUsername(String username) {
        return userRepository.findByUsername(username);
    }

    public Flux<User> getAllUsers(){
        return userRepository.findAll();
    }
    
    // 其他方法省略
}